//package com.growthserver.util;
//
//import cn.hutool.crypto.digest.DigestUtil;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.alibaba.fastjson.parser.Feature;
//import com.ly.mp.springcloudnacos.nacos.NacosConfigs;
//import ly.mp.project.common.entity.TimeOutSetting;
//import ly.mp.project.common.vo.ErrorCode;
//import ly.mp.project.common.vo.ErrorMsg;
//import ly.mp.project.common.vo.ResponseIovVO;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.http.HttpEntity;
//import org.apache.http.HttpStatus;
//import org.apache.http.NameValuePair;
//import org.apache.http.client.config.RequestConfig;
//import org.apache.http.client.methods.*;
//import org.apache.http.client.utils.HttpClientUtils;
//import org.apache.http.client.utils.URIBuilder;
//import org.apache.http.entity.StringEntity;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.message.BasicNameValuePair;
//import org.apache.http.util.EntityUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.context.annotation.Configuration;
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.InputStreamReader;
//import java.util.HashMap;
//import java.util.LinkedList;
//import java.util.List;
//import java.util.Map;
//
//@Configuration
//public class HttpUtils {
//    //添加共用httpClient
//    private static CloseableHttpClient httpClient = HttpClients.custom().evictExpiredConnections().setMaxConnTotal(900).setMaxConnPerRoute(300).build();
//    private static Logger logger = LoggerFactory.getLogger(HttpUtils.class);
//    /**
//     * post json字符串
//     * @param URL
//     * @param json
//     * @param servletRequest
//     * @return
//     */
//    public static JSONObject doPostJson(String url, String json, HttpServletRequest servletRequest, TimeOutSetting timeOutSetting) {
//        // 创建连接池
////        CloseableHttpClient httpClient = HttpClients.createDefault();
//        CloseableHttpResponse response = null;
//        // 声明呀一个字符串用来存储response
//        String result = "{\"result\":\"2002\",\"msg\":\"系统繁忙,请稍后再试\"}";
//        // 创建httppost对象
//        HttpPost httpPost = new HttpPost(url);
//        RequestConfig requestConfig = RequestConfig.custom()
//                .setConnectTimeout(timeOutSetting.getConnectTimeout())
//                .setConnectionRequestTimeout(timeOutSetting.getConnectionRequestTimeout())
//                .setSocketTimeout(timeOutSetting.getSocketTimeout()).build();
//        httpPost.setConfig(requestConfig);
//        // 给httppost对象设置json格式的参数
//        StringEntity httpEntity = new StringEntity(json,"utf-8");
//        // 设置请求格式
//        httpPost.setHeader("Content-type","application/json");
//        setPostHeader(httpPost);
//        httpPost.setHeader("Accept-Encoding","");
//        if(servletRequest!=null){
//            String UA = servletRequest.getHeader("UA");
//            if(StringUtils.isNotBlank(UA)){
//                httpPost.setHeader("UA",UA);
//            }
//            //灰度标识设置
//            String gversion = servletRequest.getHeader("gversion");
//            if (StringUtils.isNotBlank(gversion)){
//                httpPost.setHeader("gversion",gversion);
//            }else{
//                httpPost.setHeader("gversion",NacosConfigs.getPropDefaultIfEmpty("memberservice.gversion","dev-member-830"));
//            }
//            String xRequestID = servletRequest.getHeader("X-Request-ID");
//            if (StringUtils.isNotBlank(xRequestID)){
//                httpPost.setHeader("X-Request-ID",xRequestID);
//            }
//        }
//        // 传参
//        httpPost.setEntity(httpEntity);
//        // 发送请求，并获取返回值
//        try {
//            long start = System.currentTimeMillis();
//            response = httpClient.execute(httpPost);
//            InputStream in = response.getEntity().getContent();
//            BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8"));
//            StringBuilder strber= new StringBuilder();
//            String line = null;
//            while((line = br.readLine())!=null){
//                strber.append(line+'\n');
//            }
//            br.close();
//            in.close();
//            result = strber.toString();
//            //返回结果 响应码200
//            logger.info("返回参数，url:{},入参：{}，返回参数:{},spend:{}ms",url,json,result,System.currentTimeMillis()-start);
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }finally {
////            if(response != null){
////                try {
////                    response.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//            HttpClientUtils.closeQuietly(response);
//            httpPost.releaseConnection();
////            if(httpClient != null){
////                try {
////                    httpClient.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//        }
//        return  JSONObject.parseObject(result, Feature.IgnoreNotMatch);
//    }
//
//
//    /**
//     * post json字符串
//     * @param url
//     * @param json
//     * @param servletRequest
//     * @return
//     */
//    public static JSONObject doPostJsonByHeader(String url, String json,Map<String,Object> headerMap, HttpServletRequest servletRequest, TimeOutSetting timeOutSetting) {
//        // 创建连接池
////        CloseableHttpClient httpClient = HttpClients.createDefault();
//        CloseableHttpResponse response = null;
//        // 声明呀一个字符串用来存储response
//        String result = "{\"result\":\"2002\",\"msg\":\"系统繁忙,请稍后再试\"}";
//        // 创建httppost对象
//        HttpPost httpPost = new HttpPost(url);
//        RequestConfig requestConfig = RequestConfig.custom()
//                .setConnectTimeout(timeOutSetting.getConnectTimeout())
//                .setConnectionRequestTimeout(timeOutSetting.getConnectionRequestTimeout())
//                .setSocketTimeout(timeOutSetting.getSocketTimeout()).build();
//        httpPost.setConfig(requestConfig);
//        // 给httppost对象设置json格式的参数
//        StringEntity httpEntity = new StringEntity(json,"utf-8");
//        // 设置请求格式
//        httpPost.setHeader("Content-type","application/json");
//        setPostHeader(httpPost);
//        httpPost.setHeader("Accept-Encoding","");
//        if(servletRequest!=null){
//            String UA = servletRequest.getHeader("UA");
//            if(StringUtils.isNotBlank(UA)){
//                httpPost.setHeader("UA",UA);
//            }
//            //灰度标识设置
//            String gversion = servletRequest.getHeader("gversion");
//            if (StringUtils.isNotBlank(gversion)){
//                httpPost.setHeader("gversion",gversion);
//            }else{
//                httpPost.setHeader("gversion",NacosConfigs.getPropDefaultIfEmpty("memberservice.gversion","dev-member-830"));
//            }
//            String xRequestID = servletRequest.getHeader("X-Request-ID");
//            if (StringUtils.isNotBlank(xRequestID)){
//                httpPost.setHeader("X-Request-ID",xRequestID);
//            }
//        }
//        // 设置头部参数
//        for(Map.Entry<String, Object> entry : headerMap.entrySet()){
//            httpPost.setHeader(entry.getKey(), entry.getValue().toString());
//        }
//        // 传参
//        httpPost.setEntity(httpEntity);
//        // 发送请求，并获取返回值
//        try {
//            long start = System.currentTimeMillis();
//            response = httpClient.execute(httpPost);
//            InputStream in = response.getEntity().getContent();
//            BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8"));
//            StringBuilder strber= new StringBuilder();
//            String line = null;
//            while((line = br.readLine())!=null){
//                strber.append(line+'\n');
//            }
//            br.close();
//            in.close();
//            result = strber.toString();
//            //返回结果 响应码200
//            logger.info("返回参数，url:{},入参：{}，返回参数:{},spend:{}ms",url,json,result,System.currentTimeMillis()-start);
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }finally {
////            if(response != null){
////                try {
////                    response.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//            HttpClientUtils.closeQuietly(response);
//            httpPost.releaseConnection();
////            if(httpClient != null){
////                try {
////                    httpClient.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//        }
//        return  JSONObject.parseObject(result, Feature.IgnoreNotMatch);
//    }
//
//    /**
//     * put json字符串
//     * @param url
//     * @param json
//     * @param servletRequest
//     * @return
//     */
//    public static JSONObject doPutJson(String url, String json, HttpServletRequest servletRequest, TimeOutSetting timeOutSetting) {
//        String acceptLanguage = servletRequest.getHeader("acceptLanguage");
//        String lang = "zh-CN".equals(acceptLanguage) ? "cn":"en";
//        ResponseIovVO errRes = new ResponseIovVO();
//        errRes.setResult(ErrorCode.EC2002);
//        errRes.setMsg(ErrorMsg.getErrMsg(ErrorCode.EC2002,lang));
//        // 创建连接池
////        CloseableHttpClient httpClient = HttpClients.createDefault();
//        CloseableHttpResponse response = null;
//        // 声明呀一个字符串用来存储response
//        String result;
//        // 创建httppost对象
//        HttpPut httpPut = new HttpPut(url);
//        RequestConfig requestConfig = RequestConfig.custom()
//                .setConnectTimeout(timeOutSetting.getConnectTimeout())
//                .setConnectionRequestTimeout(timeOutSetting.getConnectionRequestTimeout())
//                .setSocketTimeout(timeOutSetting.getSocketTimeout()).build();
//        httpPut.setConfig(requestConfig);
//        // 给httppost对象设置json格式的参数
//        StringEntity httpEntity = new StringEntity(json,"utf-8");
//        // 设置请求格式
//        httpPut.setHeader("Content-type","application/json");
//        httpPut.setHeader("Accept-Encoding","");
//        setPutHeader(httpPut);
//        if(StringUtils.isNotBlank(acceptLanguage)){
//            httpPut.setHeader("Accept-Language",acceptLanguage);
//        }
//        String UA = servletRequest.getHeader("UA");
//        if(StringUtils.isNotBlank(UA)){
//            httpPut.setHeader("UA",UA);
//        }
//        //灰度标识设置
//        String gversion = servletRequest.getHeader("gversion");
//        if (StringUtils.isNotBlank(gversion)){
//            httpPut.setHeader("gversion",gversion);
//        }else {
//            httpPut.setHeader("gversion",NacosConfigs.getPropDefaultIfEmpty("memberservice.gversion","dev-member-830"));
//        }
//        String xRequestID = servletRequest.getHeader("X-Request-ID");
//        if (StringUtils.isNotBlank(xRequestID)){
//            httpPut.setHeader("X-Request-ID",xRequestID);
//        }
//        // 传参
//        httpPut.setEntity(httpEntity);
//        // 发送请求，并获取返回值
//        try {
//            response = httpClient.execute(httpPut);
//            InputStream in = response.getEntity().getContent();
//            BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8"));
//            StringBuilder strber= new StringBuilder();
//            String line = null;
//            while((line = br.readLine())!=null){
//                strber.append(line+'\n');
//            }
//            br.close();
//            in.close();
//            result = strber.toString();
//            //返回结果 响应码200
//            if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,json,result);
//                return JSONObject.parseObject(result);
//            }else{
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,json,result);
//                return  (JSONObject) JSONObject.toJSON(errRes);
//            }
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }finally {
////            if(response != null){
////                try {
////                    response.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//            HttpClientUtils.closeQuietly(response);
//            httpPut.releaseConnection();
////            if(httpClient != null){
////                try {
////                    httpClient.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//        }
//        return  (JSONObject) JSONObject.toJSON(errRes);
//    }
//
//
//
//    /**
//     * get 拼接url参数
//     * @param url
//     * @param paramMap
//     * @param servletRequest
//     * @return
//     * //List<NameValuePair> list = new LinkedList<>();
//     * //BasicNameValuePair param2 = new BasicNameValuePair("key2", "value2");
//     * //list.add(param1);
//     */
//    public static JSONObject doGetParam(String url, HashMap<String,Object> paramMap, HttpServletRequest servletRequest, TimeOutSetting timeOutSetting){
//        String acceptLanguage = servletRequest.getHeader("acceptLanguage");
//        String lang = "zh-CN".equals(acceptLanguage) ? "cn":"en";
//        ResponseIovVO errRes = new ResponseIovVO();
//        errRes.setResult(ErrorCode.EC2002);
//        errRes.setMsg(ErrorMsg.getErrMsg(ErrorCode.EC2002,lang));
//        //创建 CloseableHttpClient
////        CloseableHttpClient httpClient = HttpClients.createDefault();
//        CloseableHttpResponse response = null;
//        String result = null;
//        HttpGet httpGet = null;
//        try {
//            URIBuilder uri = new URIBuilder(url);
//            List<NameValuePair> paramList = new LinkedList<>();
//            if(paramMap != null){
//                for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
//                    String key = entry.getKey();
//                    String value = entry.getValue().toString();
//                    paramList.add(new BasicNameValuePair(key, value));
//                }
//            }
//
//            uri.setParameters(paramList);
//            httpGet = new HttpGet(uri.build());
//
//            RequestConfig requestConfig = RequestConfig.custom()
//                    .setConnectTimeout(timeOutSetting.getConnectTimeout())
//                    .setConnectionRequestTimeout(timeOutSetting.getConnectionRequestTimeout())
//                    .setSocketTimeout(timeOutSetting.getSocketTimeout()).build();
//            httpGet.setConfig(requestConfig);
//            httpGet.setHeader("Accept-Encoding","");
//            if(StringUtils.isNotBlank(acceptLanguage)){
//                httpGet.setHeader("Accept-Language",acceptLanguage);
//            }
//            String UA = servletRequest.getHeader("UA");
//            if(StringUtils.isNotBlank(UA)){
//                httpGet.setHeader("UA",UA);
//            }
//            //灰度的标识设置
//            String gversion = servletRequest.getHeader("gversion");
//            if (StringUtils.isNotBlank(gversion)){
//                httpGet.setHeader("gversion",gversion);
//            }else{
//                httpGet.setHeader("gversion",NacosConfigs.getPropDefaultIfEmpty("memberservice.gversion","dev-member-830"));
//            }
//            String xRequestID = servletRequest.getHeader("X-Request-ID");
//            if (StringUtils.isNotBlank(xRequestID)){
//                httpGet.setHeader("X-Request-ID",xRequestID);
//            }
//            setGetHeader(httpGet);
//            response = httpClient.execute(httpGet);
//            InputStream in = response.getEntity().getContent();
//            BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8"));
//            StringBuilder strber= new StringBuilder();
//            String line = null;
//            while((line = br.readLine())!=null){
//                strber.append(line+'\n');
//            }
//            br.close();
//            in.close();
//            result = strber.toString();
//            int status = response.getStatusLine().getStatusCode();//获取返回状态值
//            if (status == HttpStatus.SC_OK) {//请求成功
//                HttpEntity httpEntity = response.getEntity();
//                JSONObject jsonResult = JSONObject.parseObject(result);
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,JSONObject.toJSONString(paramMap),result);
//                return jsonResult;
//            }else{
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,JSONObject.toJSONString(paramMap),result);
//                return (JSONObject) JSONObject.toJSON(errRes);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
////            if(response != null){
////                try {
////                    response.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//            HttpClientUtils.closeQuietly(response);
//              if(httpGet!=null){
//                  httpGet.releaseConnection();
//              }
////            if(httpClient != null){
////                try {
////                    httpClient.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//        }
//        return (JSONObject) JSONObject.toJSON(errRes);
//    }
//
//
//    /**
//     * get 拼接url参数
//     * @param url
//     * @param paramMap
//     * @param servletRequest
//     * @return
//     * //List<NameValuePair> list = new LinkedList<>();
//     * //BasicNameValuePair param2 = new BasicNameValuePair("key2", "value2");
//     * //list.add(param1);
//     */
//    public static JSONObject doGetParamByHeader(String url, HashMap<String,Object> paramMap,Map<String,Object> headerMap, HttpServletRequest servletRequest, TimeOutSetting timeOutSetting){
//        String acceptLanguage = servletRequest.getHeader("acceptLanguage");
//        String lang = "zh-CN".equals(acceptLanguage) ? "cn":"en";
//        ResponseIovVO errRes = new ResponseIovVO();
//        errRes.setResult(ErrorCode.EC2002);
//        errRes.setMsg(ErrorMsg.getErrMsg(ErrorCode.EC2002,lang));
//        //创建 CloseableHttpClient
////        CloseableHttpClient httpClient = HttpClients.createDefault();
//        CloseableHttpResponse response = null;
//        String result = null;
//        HttpGet httpGet = null;
//        try {
//            URIBuilder uri = new URIBuilder(url);
//            List<NameValuePair> paramList = new LinkedList<>();
//            if(paramMap != null){
//                for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
//                    String key = entry.getKey();
//                    String value = entry.getValue().toString();
//                    paramList.add(new BasicNameValuePair(key, value));
//                }
//            }
//
//            uri.setParameters(paramList);
//            httpGet = new HttpGet(uri.build());
//
//            RequestConfig requestConfig = RequestConfig.custom()
//                    .setConnectTimeout(timeOutSetting.getConnectTimeout())
//                    .setConnectionRequestTimeout(timeOutSetting.getConnectionRequestTimeout())
//                    .setSocketTimeout(timeOutSetting.getSocketTimeout()).build();
//            httpGet.setConfig(requestConfig);
//            httpGet.setHeader("Accept-Encoding","");
//            if(StringUtils.isNotBlank(acceptLanguage)){
//                httpGet.setHeader("Accept-Language",acceptLanguage);
//            }
//            String UA = servletRequest.getHeader("UA");
//            if(StringUtils.isNotBlank(UA)){
//                httpGet.setHeader("UA",UA);
//            }
//            //灰度的标识设置
//            String gversion = servletRequest.getHeader("gversion");
//            if (StringUtils.isNotBlank(gversion)){
//                httpGet.setHeader("gversion",gversion);
//            }else{
//                httpGet.setHeader("gversion",NacosConfigs.getPropDefaultIfEmpty("memberservice.gversion","dev-member-830"));
//            }
//            String xRequestID = servletRequest.getHeader("X-Request-ID");
//            if (StringUtils.isNotBlank(xRequestID)){
//                httpGet.setHeader("X-Request-ID",xRequestID);
//            }
//            setGetHeader(httpGet);
//
//            // 设置头部参数
//            for(Map.Entry<String, Object> entry : headerMap.entrySet()){
//                httpGet.setHeader(entry.getKey(), entry.getValue().toString());
//            }
//            response = httpClient.execute(httpGet);
//            InputStream in = response.getEntity().getContent();
//            BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8"));
//            StringBuilder strber= new StringBuilder();
//            String line = null;
//            while((line = br.readLine())!=null){
//                strber.append(line+'\n');
//            }
//            br.close();
//            in.close();
//            result = strber.toString();
//            int status = response.getStatusLine().getStatusCode();//获取返回状态值
//            if (status == HttpStatus.SC_OK) {//请求成功
//                HttpEntity httpEntity = response.getEntity();
//                JSONObject jsonResult = JSONObject.parseObject(result);
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,JSONObject.toJSONString(paramMap),result);
//                return jsonResult;
//            }else{
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,JSONObject.toJSONString(paramMap),result);
//                return (JSONObject) JSONObject.toJSON(errRes);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
////            if(response != null){
////                try {
////                    response.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//            HttpClientUtils.closeQuietly(response);
//            if(httpGet!=null){
//                httpGet.releaseConnection();
//            }
////            if(httpClient != null){
////                try {
////                    httpClient.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//        }
//        return (JSONObject) JSONObject.toJSON(errRes);
//    }
//
//    /**
//     * get 拼接url参数
//     * @param url
//     * @param paramMap
//     * @param servletRequest
//     * @return
//     * //List<NameValuePair> list = new LinkedList<>();
//     * //BasicNameValuePair param2 = new BasicNameValuePair("key2", "value2");
//     * //list.add(param1);
//     */
//    public static JSONObject doPostParam(String url, HashMap<String,Object> paramMap, HttpServletRequest servletRequest, TimeOutSetting timeOutSetting,String acceptLanguage){
//        String lang = "zh-CN".equals(acceptLanguage) ? "cn":"en";
//        ResponseIovVO errRes = new ResponseIovVO();
//        errRes.setResult(ErrorCode.EC2002);
//        errRes.setMsg(ErrorMsg.getErrMsg(ErrorCode.EC2002,lang));
//        //创建 CloseableHttpClient
////        CloseableHttpClient httpClient = HttpClients.createDefault();
//        CloseableHttpResponse response = null;
//        String result = null;
//        HttpPost httpGet = null;
//        try {
//            URIBuilder uri = new URIBuilder(url);
//            List<NameValuePair> paramList = new LinkedList<>();
//            if(paramMap != null){
//                for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
//                    String key = entry.getKey();
//                    String value = entry.getValue().toString();
//                    paramList.add(new BasicNameValuePair(key, value));
//                }
//            }
//
//            uri.setParameters(paramList);
//            httpGet = new HttpPost(uri.build());
//            RequestConfig requestConfig = RequestConfig.custom()
//                    .setConnectTimeout(timeOutSetting.getConnectTimeout())
//                    .setConnectionRequestTimeout(timeOutSetting.getConnectionRequestTimeout())
//                    .setSocketTimeout(timeOutSetting.getSocketTimeout()).build();
//            httpGet.setConfig(requestConfig);
//            if(StringUtils.isNotBlank(acceptLanguage)){
//                httpGet.setHeader("Accept-Language",acceptLanguage);
//            }
//            if(servletRequest!=null){
//                String UA = servletRequest.getHeader("UA");
//                if(StringUtils.isNotBlank(UA)){
//                    httpGet.setHeader("UA",UA);
//                }
//                //灰度的标识设置
//                String gversion = servletRequest.getHeader("gversion");
//                if (StringUtils.isNotBlank(gversion)){
//                    httpGet.setHeader("gversion",gversion);
//                }else{
//                    httpGet.setHeader("gversion",NacosConfigs.getPropDefaultIfEmpty("memberservice.gversion","dev-member-830"));
//                }
//                String xRequestID = servletRequest.getHeader("X-Request-ID");
//                if (StringUtils.isNotBlank(xRequestID)){
//                    httpGet.setHeader("X-Request-ID",xRequestID);
//                }
//            }
//            response = httpClient.execute(httpGet);
//            int status = response.getStatusLine().getStatusCode();//获取返回状态值
//            if (status == HttpStatus.SC_OK) {//请求成功
//                HttpEntity httpEntity = response.getEntity();
//                if(httpEntity != null){
//                    result = EntityUtils.toString(httpEntity, "UTF-8");
//                    EntityUtils.consume(httpEntity);//关闭资源
//                    JSONObject jsonResult = JSONObject.parseObject(result);
//                    logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,JSONObject.toJSONString(paramMap),result);
//                    return jsonResult;
//                }
//            }else{
//                result = EntityUtils.toString(response.getEntity(), "UTF-8");
//                EntityUtils.consume(response.getEntity());//关闭资源
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,JSONObject.toJSONString(paramMap),result);
//                return (JSONObject) JSONObject.toJSON(errRes);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
////            if(response != null){
////                try {
////                    response.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//            HttpClientUtils.closeQuietly(response);
//            if(httpGet!=null){
//                httpGet.releaseConnection();
//            }
//
////            if(httpClient != null){
////                try {
////                    httpClient.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//        }
//        return (JSONObject) JSONObject.toJSON(errRes);
//    }
//
//
//    /**
//     * delete 拼接url参数
//     * @param url
//     * @param paramMap
//     * @param servletRequest
//     * @return
//     * //List<NameValuePair> list = new LinkedList<>();
//     * //BasicNameValuePair param2 = new BasicNameValuePair("key2", "value2");
//     * //list.add(param1);
//     */
//    public static JSONObject doDeleteParam(String url,HashMap<String,Object> paramMap,HttpServletRequest servletRequest){
//        String acceptLanguage = servletRequest.getHeader("acceptLanguage");
//        String lang = "zh-CN".equals(acceptLanguage) ? "cn":"en";
//        ResponseIovVO errRes = new ResponseIovVO();
//        errRes.setResult(ErrorCode.EC2002);
//        errRes.setMsg(ErrorMsg.getErrMsg(ErrorCode.EC2002,lang));
//        //创建 CloseableHttpClient
////        CloseableHttpClient httpClient = HttpClients.createDefault();
//        CloseableHttpResponse response = null;
//        String result = null;
//        HttpDelete httpDelete = null;
//        try {
//            URIBuilder uri = new URIBuilder(url);
//            List<NameValuePair> paramList = new LinkedList<>();
//            if(paramMap != null){
//                for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
//                    String key = entry.getKey();
//                    String value = entry.getValue().toString();
//                    paramList.add(new BasicNameValuePair(key, value));
//                }
//            }
//            uri.setParameters(paramList);
//            httpDelete = new HttpDelete(uri.build());
//            RequestConfig requestConfig = RequestConfig.custom()
//                    .setConnectTimeout(3000).setConnectionRequestTimeout(3000)
//                    .setSocketTimeout(3000).build();
//            httpDelete.setConfig(requestConfig);
//            httpDelete.setHeader("Accept-Encoding","");
//            if(StringUtils.isNotBlank(acceptLanguage)){
//                httpDelete.setHeader("Accept-Language",acceptLanguage);
//            }
//            String UA = servletRequest.getHeader("UA");
//            if(StringUtils.isNotBlank(UA)){
//                httpDelete.setHeader("UA",UA);
//            }
//            //灰度的标识设置
//            String gversion = servletRequest.getHeader("gversion");
//            if (StringUtils.isNotBlank(gversion)){
//                httpDelete.setHeader("gversion",gversion);
//            }else{
//                httpDelete.setHeader("gversion",NacosConfigs.getPropDefaultIfEmpty("memberservice.gversion","dev-member-830"));
//            }
//            String xRequestID = servletRequest.getHeader("X-Request-ID");
//            if (StringUtils.isNotBlank(xRequestID)){
//                httpDelete.setHeader("X-Request-ID",xRequestID);
//            }
//            response = httpClient.execute(httpDelete);
//            logger.info("httpUtils返回：{}", JSON.toJSONString(response));
//            int status = response.getStatusLine().getStatusCode();//获取返回状态值
//            if (status == HttpStatus.SC_OK) {//请求成功
//                HttpEntity httpEntity = response.getEntity();
//                if(httpEntity != null){
//                    result = EntityUtils.toString(httpEntity, "UTF-8");
//                    EntityUtils.consume(httpEntity);//关闭资源
//                    JSONObject jsonResult = JSONObject.parseObject(result);
//                    logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,JSONObject.toJSONString(paramMap),result);
//                    return jsonResult;
//                }
//            }else{
//                result = EntityUtils.toString(response.getEntity(), "UTF-8");
//                EntityUtils.consume(response.getEntity());//关闭资源
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,JSONObject.toJSONString(paramMap),result);
//                return (JSONObject) JSONObject.toJSON(errRes);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
////            if(response != null){
////                try {
////                    response.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//            HttpClientUtils.closeQuietly(response);
//            if(httpDelete!=null){
//                httpDelete.releaseConnection();
//            }
////            if(httpClient != null){
////                try {
////                    httpClient.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//        }
//        return (JSONObject) JSONObject.toJSON(errRes);
//    }
//
//    /**
//     * uuid加密解密
//     * @param url
//     * @param headMap
//     * @param bodyJson
//     * @param servletRequest
//     * @return
//     */
//    public static JSONObject doPostJsonUser(String url, Map<String, String> headMap, String bodyJson,HttpServletRequest servletRequest) {
//        String acceptLanguage = servletRequest.getHeader("Accept-Language");
//        String lang = "zh-CN".equals(acceptLanguage) ? "cn":"en";
//        ResponseIovVO errRes = new ResponseIovVO();
//        errRes.setResult(ErrorCode.EC2002);
//        errRes.setMsg(ErrorMsg.getErrMsg(ErrorCode.EC2002,lang));
//        // 创建连接池
////        CloseableHttpClient httpClient = HttpClients.createDefault();
//        CloseableHttpResponse response = null;
//        // 声明呀一个字符串用来存储response
//        String result;
//        // 创建httppost对象
//        HttpPost httpPost = new HttpPost(url);
//        RequestConfig requestConfig = RequestConfig.custom()
//                .setConnectTimeout(3000).setConnectionRequestTimeout(3000)
//                .setSocketTimeout(3000).build();
//        httpPost.setConfig(requestConfig);
//        // 给httppost对象设置json格式的参数
//        StringEntity httpEntity = new StringEntity(bodyJson,"utf-8");
//        // 设置请求格式
//        httpPost.setHeader("Content-type","application/json");
//        httpPost.setHeader("Accept-Encoding","");
//        if(StringUtils.isNotBlank(acceptLanguage)){
//            httpPost.setHeader("Accept-Language",acceptLanguage);
//        }
//        String UA = servletRequest.getHeader("UA");
//        if(StringUtils.isNotBlank(UA)){
//            httpPost.setHeader("UA",UA);
//        }
//        //灰度的标识设置
//        String gversion = servletRequest.getHeader("gversion");
//        if (StringUtils.isNotBlank(gversion)){
//            httpPost.setHeader("gversion",gversion);
//        }else{
//            httpPost.setHeader("gversion",NacosConfigs.getPropDefaultIfEmpty("memberservice.gversion","dev-member-830"));
//        }
//        String xRequestID = servletRequest.getHeader("X-Request-ID");
//        if (StringUtils.isNotBlank(xRequestID)){
//            httpPost.setHeader("X-Request-ID",xRequestID);
//        }
//        // 设置头部参数
//        for(Map.Entry<String, String> entry : headMap.entrySet()){
//            httpPost.setHeader(entry.getKey(), entry.getValue());
//        }
//        // 传参
//        httpPost.setEntity(httpEntity);
//        // 发送请求，并获取返回值
//        try {
//            response = httpClient.execute(httpPost);
//            logger.info("httpUtils返回：{}", JSON.toJSONString(response));
//            //返回结果 响应码200
//            if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
//                result = EntityUtils.toString(response.getEntity(),"UTF-8");// 返回json格式：
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,bodyJson,result);
//                return JSONObject.parseObject(result);
//            }else{
//                result = EntityUtils.toString(response.getEntity(),"UTF-8");
//                logger.info("返回参数，url:{},入参：{}，返回参数:{}",url,bodyJson,result);
//                return (JSONObject) JSONObject.toJSON(errRes);
//            }
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }finally {
////            if(response != null){
////                try {
////                    response.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//            HttpClientUtils.closeQuietly(response);
//            httpPost.releaseConnection();
////            if(httpClient != null){
////                try {
////                    httpClient.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
//        }
//        return  (JSONObject) JSONObject.toJSON(errRes);
//    }
//
//    public static  boolean isSuccess(JSONObject jsonObject){
//        String result = jsonObject.getString("result");
//        if("1".equals(result)){
//            return true;
//        }
//        return  false;
//    }
//
//    public static Map<String,Object> getHeadersMap(HttpServletRequest servletRequest) {
//        Map<String,Object> headers = new HashMap<>();
//        String gversion = servletRequest.getHeader("gversion");
//        if(StringUtils.isNotBlank(gversion)){
//            headers.put("gversion",gversion);
//        }
//        String xRequestId = servletRequest.getHeader("X-Request-ID");
//        if(StringUtils.isNotBlank(xRequestId)){
//            headers.put("X-Request-ID",xRequestId);
//        }
//        return headers;
//    }
//
//    public static void setPostHeader(HttpPost httpPost){
//        httpPost.setHeader("appid", NacosConfigs.getProp("middle.appid"));
//        httpPost.setHeader("securetkey", DigestUtil.md5Hex(NacosConfigs.getProp("middle.securetkey")));
//    }
//
//    public static void setGetHeader(HttpGet httpGet){
//        httpGet.setHeader("appid", NacosConfigs.getProp("middle.appid"));
//        httpGet.setHeader("securetkey", DigestUtil.md5Hex(NacosConfigs.getProp("middle.securetkey")));
//    }
//
//    public static void setPutHeader(HttpPut httpPut){
//        httpPut.setHeader("appid", NacosConfigs.getProp("middle.appid"));
//        httpPut.setHeader("securetkey", DigestUtil.md5Hex(NacosConfigs.getProp("middle.securetkey")));
//    }
//}
